﻿//  --------------------------------
//  Copyright (c) AW Systems, Inc. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://www.codeplex.com/SLAM/license
//  ---------------------------------

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;

namespace Slam.FieldTypes
{
	/// <summary>
	/// Editor control for SLAM ID field.  Provides interface for setting "ShowInForms" and "GenerateValue" options on SlamIdField.
	/// </summary>
	public partial class SlamIdFieldEditor : UserControl, IFieldEditor
	{	
		SlamIdField _idField;

		protected void Page_Load(object sender, EventArgs e)
		{
		}

		public bool DisplayAsNewSection
		{
			get { return true; }
		}

		public void InitializeWithField(SPField field)
		{
			_idField = field as SlamIdField;

			if (!Page.IsPostBack && _idField != null)
			{
				chkShowFieldInForms.Checked = _idField.ShowInForms;
				chkAutoGenerateValues.Checked = _idField.GenerateValue;
			}
		}

		public void OnSaveChange(SPField field, bool isNewField)
		{
			_idField = field as SlamIdField;

			_idField.ShowInForms = chkShowFieldInForms.Checked;
			_idField.GenerateValue = chkAutoGenerateValues.Checked;
			if (!_idField.GenerateValue)
			{
				_idField.Indexed = true;
				_idField.EnforceUniqueValues = true;
			}
		}
	}
}
